package com.demo.example;

import com.demo.SpringStudyApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = SpringStudyApplication.class)
public class SpringbootStartTest {
	@Autowired
    private StudentLockController studentLockController;
    @Test
    public void test(){
        normal();
    }
    public void normal(){
        System.out.println("开始时间："+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        int count=10;
        ExecutorService threadPool = Executors.newFixedThreadPool(count);
        Future<Boolean> submit = null;
        for(int i=0;i<count;i++){
            submit = threadPool.submit(() -> studentLockController.get());
        }
        try {
            submit.get();
            Thread.sleep(1500);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
        System.out.println("数量:"+studentLockController.size());
        threadPool.shutdown();
        System.out.println("结束时间："+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));


    }
}
